module.exports = (options) => {
    return async function jwtErr(ctx, next) {
        const token = ctx.request.header.authorization;
        let decode = '';
        if (token) {
            try {
                // 解码token
                decode = ctx.app.jwt.verify(token, options.jwt.secret);
                //console.log(decode);
                await next();
            } catch (error) {
                //console.log(error)
                ctx.body = options.sendJson({
                    code: options.code.UN_LOGIN,
                    message: '请重新登陆'
                });
                return;
            }
        } else {
            ctx.body = options.sendJson({
                code: options.code.UN_LOGIN,
                message: '未登录'
            });
            return;
        }
    };
}

